﻿using System;
using System.Collections.Generic;

namespace EventAggregator
{
    public static class EventAggregatorExtensions
    {
        private static readonly EventHub EventHub;

        static EventAggregatorExtensions()
        {
            EventHub = new EventHub();
        }

        public static EventMessage Send(this object eventSource, EventHub eventHub, int id, params KeyValuePair<string, object>[] parameters)
        {
            return eventHub.Resolve(eventSource).Send(new EventMessage(id, parameters));
        }

        public static EventMessageHandler Subscribe(this object eventSource, EventHub eventHub, int id, Action<EventMessage> handler)
        {
            return eventHub.Resolve(eventSource).Subscribe(id, handler);
        }

        public static void BreakEventLoop(this object eventSource, EventHub eventHub)
        {
            eventHub.BreakEventLoop();
        }

        public static EventMessage Send(this object eventSource, int id, params KeyValuePair<string, object>[] parameters)
        {
            return Send(eventSource, EventHub, id, parameters);
        }

        public static EventMessageHandler Subscribe(this object eventSource, int id, Action<EventMessage> handler)
        {
            return Subscribe(eventSource, EventHub, id, handler);
        }

        public static void BreakEventLoop(this object eventSource)
        {
            BreakEventLoop(eventSource, EventHub);
        }
    }
}